Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Profiler API to modify environment variables (#23383) #27157

Merged
merged 1 commit into from
Oct 25, 2019

Conversation

k15tfu
Copy link

@k15tfu k15tfu commented Oct 12, 2019

No description provided.

@AaronRobinsonMSFT
Copy link
Member

/cc @davmason @noahfalk

@davmason
Copy link
Member

@k15tfu do you intend for this PR to serve as an API review? There is no implementation for the method here, so I am not sure what you intend.

@k15tfu
Copy link
Author

k15tfu commented Oct 18, 2019

@davmason For the first time - yes. I wanted to be punctual and get the sign off first. After that I gonna update this PR and provide its implementation.

@k15tfu
Copy link
Author

k15tfu commented Oct 18, 2019

Anyway, I already have a draft for SetEnvironmentVariable: 6724736

Comment on lines 7018 to 7087
CONTRACTL
{
// Yay!
NOTHROW;

// Yay!
GC_NOTRIGGER;

// Yay!
MODE_ANY;

// Yay!
EE_THREAD_NOT_REQUIRED;

// Yay!
CANNOT_TAKE_LOCK;


PRECONDITION(CheckPointer(szName, NULL_NOT_OK));
PRECONDITION(CheckPointer(szValue, NULL_OK));
}
CONTRACTL_END;
Copy link
Author

@k15tfu k15tfu Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm not sure if all of them are correct

@k15tfu
Copy link
Author

k15tfu commented Oct 18, 2019

0984ef0 - added interface for GetEnvironmentVariable

@davmason
Copy link
Member

The signature for GetEnvironmentVariable looks good, I haven't looked at anything else yet

@k15tfu
Copy link
Author

k15tfu commented Oct 19, 2019

260734d - added impl for GetEnvironmentVariable

@k15tfu
Copy link
Author

k15tfu commented Oct 19, 2019

6d733da - make them async

@k15tfu
Copy link
Author

k15tfu commented Oct 19, 2019

bbbd1c4 - add szName check in SetEnvironmentVariable

@k15tfu
Copy link
Author

k15tfu commented Oct 19, 2019

298f430 - SetEnvironmentVariable returns GetLastError() in case of error

@k15tfu
Copy link
Author

k15tfu commented Oct 19, 2019

53c9792 - rebase against ToT.

@davmason now I think it's ready for review.

@davmason
Copy link
Member

I think it looks good. What testing have you done? We should confirm that environment variables flow the way you expect, if you set one a child process inherits it, and you can pick it up from managed code, etc.

CC @janvorli in case he has anything to add.

@k15tfu k15tfu force-pushed the fix-issue-23383 branch 2 times, most recently from 1f73dd0 to f712d07 Compare October 24, 2019 15:58
@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

f712d07 - fix log messages

@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

0aa7e76 - GetEnvironmentVariable returns S_OK (not ERROR_INSUFFICIENT_BUFFER) if buffer is nullptr. For example, GetEnvironmentVariable(u"TEST_MY_VAR", 0, &outSize, nullptr) will always return S_OK if TEST_MY_VAR exists.

@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

15ed902 - code style fixes

@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

c4c0ede - rebase against ToT

@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

@davmason Yes, everything is fine now. I can get, set a new, override, or delete an environment variable as we expect. Also, after setting a new variable in Initialize callback it's passed into child processes.

@k15tfu
Copy link
Author

k15tfu commented Oct 24, 2019

@davmason I have also checked that it can be used asynchronously: I did a test, where C# in a loop updates env_var := env_var + 1 if env_var is even, and the profiler does the same thing but if env_var is odd. After 5 seconds they reached 120K.

@k15tfu k15tfu requested review from janvorli and davmason October 24, 2019 17:32
@k15tfu
Copy link
Author

k15tfu commented Oct 25, 2019

@davmason Nice. What should we do next to backport it to 3.1? Could you create a PR for that?

@davmason davmason merged commit 457449f into dotnet:master Oct 25, 2019
@davmason
Copy link
Member

davmason commented Oct 25, 2019

@k15tfu I am starting the process of requesting the 3.1 port. I should know more early next week.

One of the things I will be asked is what is the impact of not having this. If you could provide information about how this will impact your profiler that would help.

@k15tfu k15tfu deleted the fix-issue-23383 branch October 28, 2019 12:48
@k15tfu
Copy link
Author

k15tfu commented Oct 28, 2019

@davmason Without this, we can lost all of our features related to child processes: 1) ability to profile child processes (for details see https://github.com/dotnet/coreclr/issues/23383#issuecomment-514587669), 2) ability to take snapshots automatically depending on child processes hierarchy, 3) unit-testing profiler support. Most likely, end user experience will be significantly worsened if our "tricks" stop working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants